package net.oschina.app;

import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

import com.robotium.solo.By;
import com.robotium.solo.Solo;
import com.robotium.solo.WebElement;

import java.util.List;

import static net.oschina.app.R.id.view;

/**
 * Created by kola on 2017/3/21.
 * 封装solo；(方法如需修改，只需要修改一次即可，如每个方法添加log输出）
 * 封装常用方法
 */

public class SoloWrap {
    private Solo solo;
    public Object getCurrentViews;
    public Object getWebElements;

    //    让外界给solo初始化，避免为空（将一个参数的值赋给当前对象的属性）
    public SoloWrap(Solo solo) {

        this.solo = solo;
    }

    public void clickOnView(View view) {
        solo.waitForView(view, 1, 5000, false);
        Log.i("AUTO", "==============" + view.getId());
        solo.clickOnView(view);
    }

    public View getView(String id) {
        try {
            return solo.getView(id);
        } catch (Exception ex) {
            return null;
        }
    }

    public ImageButton getImageButton(int index) {

        return solo.getImageButton(index);
    }

    public void enterText(EditText et, String text) {
        Log.i("AUTO", "============================entertext" + text);
        solo.enterText(et, text);
    }

    public void clearEditText(EditText et) {
        Log.i("AUTO", "============================clear text");
        solo.clearEditText(et);
    }

    public boolean waitForText(String text) {

        return solo.waitForText(text, 0, 5000, false, true);
    }

    public void searchText(String text) {
        solo.searchText(text, false);
    }


    public void sleep(int i) {
        solo.sleep(i * 1000);
    }

    public List<WebElement> getWebElements(By by){
        return solo.getWebElements(by);
    }

}
